package lev01_beginnerClass.class02_sort;

import java.util.Arrays;

/**
 * selection sort
 */
public class L01_selectionSort {
    public static void main(String[] args) {
        int[] num = {3,4,6,4,2,6,8,6,85,8,9,894,8,9,3};
        //before selection sort
        System.out.println(Arrays.toString(num));

        selectionSort(num);
        //after selection sort
        System.out.println(Arrays.toString(num));
    }

    public static void selectionSort(int num[]){
        //give priority to boundary condition
        if(num == null || num.length<=1){
            return;
        }

        int n = num.length;

        for(int i = 0 ;i<=n-1;i++){
            int minIndex = i;
            for(int j = i;j<=n-1;j++){
                minIndex = num[j] < num[minIndex] ? j:minIndex;
            }
            swap(num,i,minIndex);
        }
    }


    public static void swap(int num[],int i,int j){
        int temp = num[i];
        num[i] = num[j];
        num[j] = temp;
    }
}
